/*
 * Copyright (c) 2015-2018 SHENZHEN JST SCIENCE AND TECHNOLOGY DEVELOP CO., LTD. All rights reserved.
 *
 * 注意：本内容仅限于深圳市捷顺金科研发有限公司内部传阅，禁止外泄以及用于其他的商业目的
 */
package com.jaws.demo.mq;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

/**
 * 消费者
 *
 * @author maojian
 * @date 2018-02-11 15:05:03
 * @since v1.0.0
 */
@Configuration
@Slf4j
public class MqConsumer {

    @Autowired
    private AmqpTemplate amqpTemplate;


    /**
     * 监听队列 详细配置
     *
     *
     * @param message
     */
    @RabbitListener(
            bindings = {
                    @QueueBinding(
                            value = @Queue(value = "jaws.topic.message1", durable = "true"),
                            exchange = @Exchange(value = "jaws.topic.exchange",
                                    type = ExchangeTypes.TOPIC),
                            key = "jaws.topic.message1")})
    public void processMessage1(Message message) {
        log.info("MqConsumer=======================收到mq信息：" + new String(message.getBody()));
    }


    /**
     * 监听队列 简单配置
     *
     * @param message
     */
    @RabbitListener(queues = {"jaws.topic.message2"})
    public void processMessage2(Message message) {
        log.info("MqConsumer2=======================收到mq信息：" + new String(message.getBody()));
    }

	/*@RabbitListener(
			bindings = {
					@QueueBinding(
							value = @Queue(value = "jaws.dead.letter", durable = "true",
							arguments= {@Argument(name="x-message-ttl",value="10000",type="java.lang.Long"),
							@Argument(name="x-dead-letter-exchange",value="jaws.topic.exchange"),
							@Argument(name="x-dead-letter-routing-key",value="jaws.topic.target")}),
							exchange = @Exchange(value = "jaws.topic.exchange",
							type = ExchangeTypes.TOPIC),
							key = "jaws.topic.message3"),
					@QueueBinding(
							value = @Queue(value = "jaws.target.message", durable = "true"),
							exchange = @Exchange(value = "jaws.topic.exchange",
									type = ExchangeTypes.TOPIC),
							key = "jaws.topic.target")})
	public void processMessage3(Message message) {
		log.info("MqConsumer3=======================收到mq信息：" + new String(message.getBody()));
	}*/


    /*@RabbitListener(
            bindings = {
                    @QueueBinding(
                            value = @Queue(value = "jaws.delayed.topic.message1", durable = "true"),
                            exchange = @Exchange(value = "jaws.delayed.topic.exchange", type = ExchangeTypes.TOPIC),
                            key = "test")})
    @RabbitListener(queues = {"jaws.delayed.topic.message1"})
    public void processMessage4(Message message) {
        log.info("MqConsumer4=======================收到mq信息：" + new String(message.getBody()));
    }*/


    /**
     * 测试  当binding队列不存在  是否自动新建
     *
     * @param message
     */
   /* @RabbitListener(
            bindings = {
                    @QueueBinding(
                            value = @Queue(value = "jaws.topic.messageautobuild", durable = "true"),
                            exchange = @Exchange(value = "jaws.topic.exchange",
                                    type = ExchangeTypes.TOPIC),
                            key = "jaws.topic.messageautobuild")})
    @RabbitListener(queues = {"jaws.topic.messageautobuild"})
    public void processMessageAutoBuildQ(Message message) {
        log.info("MqConsumer=============jaws.topic.messageautobuild==========收到mq信息：" + new String(message.getBody()));
    }*/

}
